package net.xdclass.shopproject.domain;

import org.springframework.beans.factory.FactoryBean;

public class ProductFactoryBean implements FactoryBean<Product> {

    /**
     * 标题,价格,库存
     */
    private String productInfo;

    public ProductFactoryBean() {
        System.out.println("ProductFactoryBean-------------构造函数执行");
    }

    public void setProductInfo(String productInfo) {
        this.productInfo = productInfo;
    }


    @Override
    public Product getObject() throws Exception {
        Product product = new Product();
        String[] split = productInfo.split(",");
        product.setTitle(split[0]);
        product.setPrice(Integer.valueOf(split[1]));
        product.setStock(Integer.valueOf(split[2]));
        return product;
    }

    @Override
    public Class<?> getObjectType() {
        return Product.class;
    }

    @Override
    public boolean isSingleton() {
        return FactoryBean.super.isSingleton();
    }


}
